import java.util.Stack;

public class EvalRpn {

    public static int evalRPN(String[] tokens) {
        Stack<Integer> stack = new Stack<>();
        for (int i = 0; i < tokens.length; i++) {
            String str = tokens[i];
            if(isNumber(str)){
                int number = Integer.parseInt(str);
                stack.push(number);
            }else{
                int numUp = stack.pop();
                int numSec = stack.pop();
                switch (str){
                    case "+":
                        stack.push(numUp + numSec);
                        break;
                    case "-":
                        stack.push(numSec - numUp);
                        break;
                    case "*":
                        stack.push(numSec * numUp);
                        break;
                    case "/":
                        stack.push(numSec / numUp);
                }
            }
        }
        return stack.pop();
    }
    public static boolean isNumber(String str){
        if (str.equals("+") || str.equals("-") || str.equals("*") || str.equals("/")){
            return false;
        }
        return true;
    }
}
